package com.lcredu.springboot.lamada;

/**
 * @author 黎长容
 * @date 2025-08-20 19:17
 */
public class Test {
    public static void main(String[] args) {
        //普通匿名内部类实现
//        LcrFunction<Desk, String> lf = new LcrFunction<Desk, String>() {
//            @Override
//            public String apply(Desk desk) {
//                return "hello,desk";
//            }
//        };
//        String apply = lf.apply(new Desk());
//        System.out.println(apply);

        //函数式方法实现
//        LcrFunction<Desk, String> lf2 = Desk::getName;
//        String apply = lf2.apply(new Desk());
//        System.out.println(apply);

        LcrFunction<Desk, Double> lf3 = Desk::getPrice;
        Double apply = lf3.apply(new Desk());
        System.out.println(apply);

    }
}


//模拟一个函数式接口
@FunctionalInterface
interface LcrFunction<T, R> {
    R apply(T t);

    //也可以实现默认方法
    default public void satHi() {
        System.out.println("hi");
    }

}

@FunctionalInterface
interface HspInterface {
    public void hi();
}

//模拟一个类
class Desk {
    private String name = "黎长容";
    private Double price = 99.63;

    public String getName() {
        return name;
    }

    public Double getPrice() {
        return price;
    }
}
